import 'package:bit_fury/http/request_api.dart';

import '../model/base_response.dart';
import 'base_api_service.dart';

class WalletService extends BaseApiService {
  /// 获取用户收益数据
  /// API返回格式: {"code":200,"message":"success","data":{"btc_num":"0.000013258704712","list":[...]}}
  Future<BaseResponse<Map<String, dynamic>>> getUserEarnings({int page = 1 , int pageSize = 10}) async {
    return await post<Map<String, dynamic>>(
      RequestApi.GET_EARNINGS_LIST,
      data:{
        'page': page,
        'page_size': pageSize,
      } ,
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 获取提现记录列表
  /// API返回格式: {"code":200,"message":"success","data":{"list":[...]}}
  Future<BaseResponse<Map<String, dynamic>>> getWithdrawRecords({int page = 1 , int pageSize = 10}) async {
    return await post<Map<String, dynamic>>(
      RequestApi.GET_WITHDRAW_RECORDS,
      data:{
        'page': page,
        'page_size': pageSize,
      } ,
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 获取提现页面数据
  /// API返回格式: {"code":200,"message":"success","data":{"network":[...],"amount":"0.000000000000000"}}
  Future<BaseResponse<Map<String, dynamic>>> getWithdrawPageData() async {
    return await post<Map<String, dynamic>>(
      RequestApi.GET_WITHDRAW_PAGE_DATA, // 或者您实际的API端点
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 提交提现申请
  Future<BaseResponse<Map<String, dynamic>>> submitWithdrawRequest( String amount,
  String address,
  int networkId,
  ) async {
      final data = {
        'amount': amount,
        'address': address,
        'network_id': networkId,
    };
    print('提交提现申请数据: $data');
    return await post<Map<String, dynamic>>(
      RequestApi.SUBMIT_WITHDRAW_REQUEST,
      data:data,
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 发送提现验证码
  Future<BaseResponse<Map<String, dynamic>>> sendWithdrawVerificationCode() async {
    return await post<Map<String, dynamic>>(
      '/wallet/withdraw/send-code',
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 验证钱包地址
  Future<BaseResponse<Map<String, dynamic>>> validateWalletAddress(
    String address,
    String network,
  ) async {
    return await post<Map<String, dynamic>>(
      '/wallet/validate-address',
      data: {
        'address': address,
        'network': network,
      },
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  /// 获取网络费用
  Future<BaseResponse<Map<String, dynamic>>> getNetworkFee(
    String network,
    double amount,
  ) async {
    return await get<Map<String, dynamic>>(
      '/wallet/network-fee',
      params: {
        'network': network,
        'amount': amount,
      },
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }

  // 如果您还需要获取钱包基本信息的API，可以保留这个方法
  /// 获取钱包基本信息（如果有单独的API）
  Future<BaseResponse<Map<String, dynamic>>> getWalletInfo() async {
    return await get<Map<String, dynamic>>(
      '/wallet/info',
      showLoading: true,
      fromJsonT: (json) => json as Map<String, dynamic>,
    );
  }
}